package com.bytedance.testtools

import android.app.Activity
import android.os.Bundle
import android.util.TypedValue
import android.util.TypedValue.COMPLEX_UNIT_DIP
import android.view.Gravity
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import android.view.Window
import android.widget.Button
import android.widget.FrameLayout
import android.widget.ProgressBar
import com.bytedance.testtools.view.TrackDrawView

class TrackDrawActivity : Activity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        requestWindowFeature(Window.FEATURE_NO_TITLE)
        findViewById<FrameLayout>(android.R.id.content).apply {
            removeAllViews()
            val view = TrackDrawView(this@TrackDrawActivity)
            view.layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT)
            addView(view)

            val button = Button(this@TrackDrawActivity)
            button.setOnClickListener {
                view.clear()
            }
            button.text = "clear"
            button.layoutParams = FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT, Gravity.TOP or Gravity.CENTER_HORIZONTAL)
            addView(button)

            val progress = ProgressBar(this@TrackDrawActivity)
            val size = TypedValue.applyDimension(COMPLEX_UNIT_DIP, 30f, resources.displayMetrics).toInt()
            addView(progress, FrameLayout.LayoutParams(size, size, Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL))

        }
    }
}
